//
//  TogetherController.m
//  i5db
//
//  Created by iMuse on 15-5-11.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "MyActivityController.h"
#import "AppCenter.h"
#import "PullTableView.h"
#import "TogetherDetailController.h"
#import "CredateTogrtherController.h"
#import "MyActivityDetailController.h"
#define cellHeight 100

@interface MyActivityController ()<UITableViewDataSource,UITableViewDelegate,PullTableViewDelegate>
{
    PullTableView * pullTableView;
    NSArray       * dataArray;
}

@end

@implementation MyActivityController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"我的聚会";
        dataArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
    }
    return self;
}

-(void)updateViewConstraints
{
    [super updateViewConstraints];
    [pullTableView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}
-(void) initNavigationBar
{
    [super initNavigationBar];
    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 44, 44);
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:@"创建" forState:UIControlStateNormal];
    
    /* [button setImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateNormal];
     [button setImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateSelected];
     */
    
    [button addTarget:self action:@selector(credateActivity:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *temporaryBarButtonItem2 = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    temporaryBarButtonItem2.style = UIBarButtonItemStylePlain;
    
    self.navigationItem.rightBarButtonItem = temporaryBarButtonItem2;
}
-(void)credateActivity:(UIButton*)button
{
    CredateTogrtherController * controller = [[CredateTogrtherController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setNeedsUpdateConstraints];
    [self initNavigationBar];
    [self initView];
}
-(void) initView
{
    
    pullTableView  = [PullTableView newAutoLayoutView];
    [pullTableView setDataSource:self];
    [pullTableView setDelegate:self];
    [pullTableView setPullDelegate:self];
    [pullTableView setRefreshType:PRPullUpLoadMore];
    
    [self.view addSubview:pullTableView];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString* identifier = @"i5dbIndefter";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    UILabel         * line          = nil;
    UIImageView     * imageView     = nil;
    UILabel         * projectLabel  = nil;
    UIImageView     * locImageView  = nil;
    UILabel         * locationLabel = nil;
    UIImageView     * timeImageView = nil;
    UILabel         * timeLabel     = nil;
    UIImageView     * personImageView = nil;
    UILabel         * personLabel   = nil;
    UILabel         * acitivityPersonLabel = nil;
    tableView.separatorStyle = NO;
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:identifier] ;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        line = [UILabel newAutoLayoutView];
        line.backgroundColor = [AppCenter color:@"225,225,225,1"];
        [cell.contentView addSubview:line];
        [line autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
        [line autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
        [line autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
        [line autoSetDimension:ALDimensionHeight toSize:5];
        
        imageView = [UIImageView newAutoLayoutView];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.image = [UIImage imageNamed:@"woman2.png"];
        imageView.tag = 1;
        [cell.contentView addSubview:imageView];
        [imageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:2];
        [imageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:2];
        [imageView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:7];
        [imageView autoSetDimension:ALDimensionWidth toSize:cell.contentView.frame.size.width/4];
        
        projectLabel = [UILabel newAutoLayoutView];
        projectLabel.font = [UIFont systemFontOfSize:14];
        projectLabel.numberOfLines = 0;
        projectLabel.text = @"一场只属于单身贵族的Party";
        projectLabel.tag = 2;
        [cell.contentView addSubview:projectLabel];
        [projectLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:5];
        [projectLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:5];
        [projectLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [projectLabel autoSetDimension:ALDimensionHeight toSize:cellHeight/2];
        
        locImageView = [UIImageView newAutoLayoutView];
        locImageView.image = [UIImage imageNamed:@"group_card_distance.png"];
        [cell.contentView addSubview:locImageView];
        [locImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:projectLabel withOffset:0];
        [locImageView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:5];
        [locImageView autoSetDimensionsToSize:CGSizeMake(10, 12)];
        
        locationLabel = [UILabel newAutoLayoutView];
        locationLabel.tag = 3;
        locationLabel.text = @"欢乐谷";
        locationLabel.font = [UIFont systemFontOfSize:12];
        locationLabel.textColor = [AppCenter color:@"126,126,126,1"];
        [cell.contentView addSubview:locationLabel];
        [locationLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:locImageView withOffset:5];
        [locationLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:projectLabel withOffset:0];
        [locationLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [locationLabel autoSetDimension:ALDimensionHeight toSize:12];
        
        acitivityPersonLabel = [UILabel newAutoLayoutView];
        acitivityPersonLabel.text = @"举办人:王国栋";
        [cell.contentView addSubview:acitivityPersonLabel];
        acitivityPersonLabel.font = [UIFont systemFontOfSize:10];
        acitivityPersonLabel.textColor = [AppCenter color:@"76,187,248,1"];
        [acitivityPersonLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [acitivityPersonLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:projectLabel withOffset:0];
        
        
        timeImageView = [UIImageView newAutoLayoutView];
        timeImageView.image = [UIImage imageNamed:@"mqz_ugc_btn_time.png"];
        [cell.contentView addSubview:timeImageView];
        [timeImageView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:5];
        [timeImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locImageView withOffset:5];
        [timeImageView autoSetDimensionsToSize:CGSizeMake(10, 10)];
        
        timeLabel     = [UILabel newAutoLayoutView];
        timeLabel.tag = 4;
        timeLabel.text = @"周日 2015/12/23";
        timeLabel.font = locationLabel.font;
        timeLabel.textColor = locationLabel.textColor;
        [cell.contentView addSubview:timeLabel];
        [timeLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:locationLabel withOffset:0];
        [timeLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locationLabel withOffset:5];
        [timeLabel autoSetDimension:ALDimensionHeight toSize:10];
        [timeLabel autoSetDimension:ALDimensionWidth toSize:100];
        
        personLabel = [UILabel newAutoLayoutView];
        personLabel.tag = 5;
        personLabel.text = @"160";
        personLabel.font = locationLabel.font;
        personLabel.textColor = locationLabel.textColor;
        [cell.contentView addSubview:personLabel];
        [personLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [personLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locationLabel withOffset:5];
        [personLabel autoSetDimension:ALDimensionHeight toSize:10];
        
        personImageView = [UIImageView newAutoLayoutView];
        personImageView.image = [UIImage imageNamed:@"circle_new_friend_empty.png"];
        [cell.contentView addSubview:personImageView];
        [personImageView autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:personLabel withOffset:0];
        [personImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locationLabel withOffset:5];
        [personImageView autoSetDimensionsToSize:CGSizeMake(10, 10)];
        
        
    }else
    {
        
        
    }
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return dataArray.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return cellHeight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyActivityDetailController * controller = [[MyActivityDetailController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}



- (void)viewWillAppear:(BOOL)animated {
    
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    [super viewWillAppear:animated];
    
    
}


- (void)viewWillDisappear:(BOOL)animated {
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}



@end
